/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: MyCollectionActivity
 * Author: Gxjkz
 * Date: 2021/8/4 10:51
 * Description: 我的收藏
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.niuxiaofa.newlaw.Activity;


import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.google.android.material.tabs.TabLayout;
import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.adapter.CustomViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @ClassName: MyCollectionActivity
 * @Description: 我的收藏
 * @Author: Gxjkz
 * @Date: 2021/8/4 10:51
 */
public class MyCollectionActivity extends BaseActivity {

    private FragmentPagerAdapter fragmentPagerAdapter;

    private String[] tabTxt = {"动态", "视频"};

    private List<Fragment> mFragments = new ArrayList<>();

    int currentPage = 0;

    @BindView(R.id.customViewPager)
    CustomViewPager customViewPager;

    @BindView(R.id.tablayout_holder)
    TabLayout holderTabLayout;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_mycollection;
    }

    @Override
    protected void initData() {

        setTitle("我的收藏");

        fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        };


        customViewPager.setOffscreenPageLimit(4);
        customViewPager.setScanScroll(true);
        customViewPager.setAdapter(fragmentPagerAdapter);

        for (int i = 0; i < tabTxt.length; i++) {
            holderTabLayout.addTab(holderTabLayout.newTab().setText(tabTxt[i]));
        }
        //实际的tablayout的点击切换
        holderTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int pos = tab.getPosition();
                customViewPager.setCurrentItem(pos);
                currentPage = pos;

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }
}